import mazeUtils from './useMaze'
import { ref } from 'vue'
export const useEffects = () => {
    const effects = ref([]) // 特效列表
    const effectCount = ref(3) // 特效数量

    // 初始化特效
    const initEffects = () => {
        // 先清空特效
        effects.value = []
        const positions = mazeUtils.generateMultipleValidPositions(effectCount.value)
        for (let i = 0; i < effectCount.value; i++) {
            const position = positions[i] || { row: 0, col: 0 }
            effects.value.push({
                id: `effect-${i + 1}`,
                position: { row: position.row, col: position.col },
                type: 'effect',
                color: 'red'
            })
        }
    }
    // 判断猫咪的位置是否在特性的位置上
    const isCatInEffect = (cat,effect) => {
        return cat.position.row === effect.position.row && cat.position.col === effect.position.col
    }
    // 判断猫咪是否吃到了特性
    const catEatEffect = (cat) => {
        const effect = effects.value.find(effect => isCatInEffect(cat,effect))
        // 如果吃到了特性，需要删除特性
        if (effect) {
            effects.value = effects.value.filter(item => item.id !== effect.id)
            return true
        }
        return false
    }


    return { effects, effectCount, initEffects,catEatEffect,isCatInEffect }
}